package 数组题目.数组变换;

//最长公共前缀
//https://leetcode.cn/problems/longest-common-prefix/description/
class 最长公共前缀 {
    public String longestCommonPrefix(String[] strs) {
        String commonPrefix = strs[0];
        for (int i = 1; i < strs.length; i++) {
            int len = Math.min(commonPrefix.length(), strs[i].length());
            int cur = 0;
            while (cur < len) {
                if (commonPrefix.charAt(cur) != strs[i].charAt(cur)) {
                    break;
                }
                cur++;
            }
            commonPrefix = commonPrefix.substring(0, cur);
        }
        return commonPrefix;
    }
}
